<template>
  <div>
    <header class="header">
      <h1>todos</h1>
      <input
        class="new-todo"
        placeholder="请输入任务名称"
        v-model="stringName"
        @keyup.enter="addEvent(stringName)"
        autofocus
      />
    </header>
  </div>
</template>

<script>
export default {
  name: 'HeaderTodo',
  components: {},
  props: {},
  data() {
    return {
      stringName: ''
    }
  },
  computed: {},
  watch: {},
  created() {},
  methods: {
    // 回车弹起的添加事件
    addEvent(value) {
      if (this.stringName === '') return alert('内容不能为空')
      this.$emit('addEvent', value)
      this.stringName = ''
    }
  }
}
</script>

<style scoped></style>
